import { getCssVariableValue } from '@/utils/utils';

/** 表格配置 */
const getTableColumns = (marketId) => {
  if (marketId === 'PDBLJ') {
    return [
      { dataIndex: 'date', title: '日期', width: 100, fixed: 'left', align: 'center' },
      {
        dataIndex: 'dayaheadThermalPeriodNum',
        title: '火电开机台数',
        width: 100,
        fixed: 'left',
        align: 'center',
      },
      {
        dataIndex: 'dayAheadClearingPrice',
        title: '日前现货市场出清价格',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayAheadClearingPriceMax', title: '最高', width: 100, align: 'center' },
          { dataIndex: 'dayAheadClearingPriceMin', title: '最低', width: 100, align: 'center' },
          { dataIndex: 'dayAheadClearingPriceAvg', title: '平均', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'realtimeClearingPrice',
        title: '实时现货市场出清价格',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'realtimeClearingPriceMax', title: '最高', width: 100, align: 'center' },
          { dataIndex: 'realtimeClearingPriceMin', title: '最低', width: 100, align: 'center' },
          { dataIndex: 'realtimeClearingPriceAvg', title: '平均', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'dayAheadLoadForecast',
        title: '省内负荷-日前',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayAheadLoadForecastMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'dayAheadLoadForecastMin', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'realtimeLoad',
        title: '省内负荷-实时',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'realtimeLoadMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'realtimeLoadMin', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'dayLoadRealtime',
        title: '省内负荷偏差',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayMaxLoadRealtime', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'dayMinLoadRealtime', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'dayAheadLink',
        title: '联络线外送-日前',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayAheadLinkMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'dayAheadLinkMin', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'realtimeLink',
        title: '联络线外送-实时',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'realtimeLinkMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'realtimeLinkMin', title: '最小', width: 100, align: 'center' },
        ],
      },
    ];
  } else if (marketId === 'PXBNX') {
    return [
      { dataIndex: 'date', title: '日期', width: 100, fixed: 'left', align: 'center' },
      {
        dataIndex: 'dayAheadClearingPrice',
        title: '日前现货市场出清价格',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayAheadClearingPriceMax', title: '最高', width: 100, align: 'center' },
          { dataIndex: 'dayAheadClearingPriceMin', title: '最低', width: 100, align: 'center' },
          { dataIndex: 'dayAheadClearingPriceAvg', title: '平均', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'realtimeClearingPrice',
        title: '实时现货市场出清价格',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'realtimeClearingPriceMax', title: '最高', width: 100, align: 'center' },
          { dataIndex: 'realtimeClearingPriceMin', title: '最低', width: 100, align: 'center' },
          { dataIndex: 'realtimeClearingPriceAvg', title: '平均', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'dayAheadLoadForecast',
        title: '省内负荷-日前',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayAheadLoadForecastMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'dayAheadLoadForecastMin', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'realtimeLoad',
        title: '省内负荷-实时',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'realtimeLoadMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'realtimeLoadMin', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'dayLoadRealtime',
        title: '省内负荷偏差',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayMaxLoadRealtime', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'dayMinLoadRealtime', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'dayAheadLink',
        title: '联络线外送-日前',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayAheadLinkMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'dayAheadLinkMin', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'realtimeLink',
        title: '联络线外送-实时',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'realtimeLinkMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'realtimeLinkMin', title: '最小', width: 100, align: 'center' },
        ],
      },
    ];
  } else {
    return [
      { dataIndex: 'date', title: '日期', width: 100, fixed: 'left', align: 'center' },
      {
        dataIndex: 'dayaheadThermalPeriodNum',
        title: '火电开机台数',
        width: 100,
        fixed: 'left',
        align: 'center',
      },
      {
        dataIndex: 'dayaheadThermalPeriodCapacity',
        title: '机组运行容量',
        width: 100,
        fixed: 'left',
        align: 'center',
      },
      {
        dataIndex: 'dayAheadClearingPrice',
        title: '日前现货市场出清价格',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayAheadClearingPriceMax', title: '最高', width: 100, align: 'center' },
          { dataIndex: 'dayAheadClearingPriceMin', title: '最低', width: 100, align: 'center' },
          { dataIndex: 'dayAheadClearingPriceAvg', title: '平均', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'realtimeClearingPrice',
        title: '实时现货市场出清价格',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'realtimeClearingPriceMax', title: '最高', width: 100, align: 'center' },
          { dataIndex: 'realtimeClearingPriceMin', title: '最低', width: 100, align: 'center' },
          { dataIndex: 'realtimeClearingPriceAvg', title: '平均', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'dayAheadLoadForecast',
        title: '省内负荷-日前',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayAheadLoadForecastMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'dayAheadLoadForecastMin', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'realtimeLoad',
        title: '省内负荷-实时',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'realtimeLoadMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'realtimeLoadMin', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'dayLoadRealtime',
        title: '省内负荷偏差',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayMaxLoadRealtime', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'dayMinLoadRealtime', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'dayAheadLink',
        title: '联络线外送-日前',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'dayAheadLinkMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'dayAheadLinkMin', title: '最小', width: 100, align: 'center' },
        ],
      },
      {
        dataIndex: 'realtimeLink',
        title: '联络线外送-实时',
        width: 100,
        align: 'center',
        children: [
          { dataIndex: 'realtimeLinkMax', title: '最大', width: 100, align: 'center' },
          { dataIndex: 'realtimeLinkMin', title: '最小', width: 100, align: 'center' },
        ],
      },
    ];
  }
};

/** 图：系列配置 */
const _SERIES = {
  // 全省现货日间出清电价对比
  dayAheadClearingPriceMax: { name: '日前出清价最高', type: 'dashed', color: '#C1D1FA' },
  dayAheadClearingPriceAvg: { name: '日前出清价平均', type: 'dashed', color: '#5E92F6' },
  dayAheadClearingPriceMin: { name: '日前出清价最低', type: 'dashed', color: '#4C72B9' },
  realtimeClearingPriceMax: { name: '实时出清价最高', type: 'line', color: '#F5C2B8' },
  realtimeClearingPriceAvg: { name: '实时出清价平均', type: 'line', color: '#E86452' },
  realtimeClearingPriceMin: { name: '实时出清价最低', type: 'line', color: '#994B42' },
  // 省内负荷日间对比
  dayAheadLoadForecastMax: { name: '日前负荷预测最大', type: 'dashed', color: '#C1D1FA' },
  dayAheadLoadForecastMin: { name: '日前负荷预测最小', type: 'dashed', color: '#4C72B9' },
  realtimeLoadMax: { name: '实时负荷最大', type: 'line', color: '#F5C2B8' },
  realtimeLoadMin: { name: '实时负荷最小', type: 'line', color: '#994B42' },
  // 省间联络线(外送值)日间对比
  dayAheadLinkMax: { name: '日前联络线最大', type: 'dashed', color: '#C1D1FA' },
  dayAheadLinkMin: { name: '日前联络线最小', type: 'dashed', color: '#4C72B9' },
  realtimeLinkMax: { name: '实时联络线最大', type: 'line', color: '#F5C2B8' },
  realtimeLinkMin: { name: '实时联络线最小', type: 'line', color: '#994B42' },
  // 省内负荷最值偏差日间对比
  dayMaxLoadRealtime: { name: '日最大负荷日前-实时', type: 'bar', color: '#C1D1FA' },
  dayMinLoadRealtime: { name: '日最小负荷日前-实时', type: 'bar', color: '#4C72B9' },
};

// 图：配置
const charts = [
  {
    title: '全省现货日间出清电价对比',
    unit: '单位: 元/MWh',
    dimensions: [
      'dayAheadClearingPriceMax',
      'dayAheadClearingPriceAvg',
      'dayAheadClearingPriceMin',
      'realtimeClearingPriceMax',
      'realtimeClearingPriceAvg',
      'realtimeClearingPriceMin',
    ],
  },
  {
    title: '省内负荷日间对比',
    unit: '单位: MW',
    dimensions: [
      'dayAheadLoadForecastMax',
      'dayAheadLoadForecastMin',
      'realtimeLoadMax',
      'realtimeLoadMin',
    ],
  },
  {
    title: '省间联络线(外送值)日间对比',
    unit: '单位: MW',
    dimensions: ['dayAheadLinkMax', 'dayAheadLinkMin', 'realtimeLinkMax', 'realtimeLinkMin'],
  },
  {
    title: '省内负荷最值偏差日间对比',
    unit: '单位: MW',
    dimensions: ['dayMaxLoadRealtime', 'dayMinLoadRealtime'],
  },
];

// 图：获取配置
const getChartOption = (dataSource = [], config) => {
  return {
    grid: { top: 24, left: 48, bottom: 56, right: 2 },
    dataset: {
      dimensions: ['date', ...config.dimensions],
      source: dataSource,
    },
    series: config.dimensions.map((k) => _SERIES[k]),
    tooltip: {},
    legend: {
      textStyle: {
        color: getCssVariableValue('--chart-legend-color'),
      },
    },
    xAxis: [
      {
        type: 'category',
        formatter: (v) => v.slice(4),
        axisLabel: {
          color: getCssVariableValue('--chart-font-color'),
        },
        axisLine: {
          lineStyle: {
            type: 'solid',
            color: getCssVariableValue('--chart-x-line'),
          },
        },
        axisTick: {
          lineStyle: {
            color: getCssVariableValue('--chart-x-line'),
          },
        },
        axisPointer: {
          type: 'line',
          lineStyle: {
            color: getCssVariableValue('--chart-x-line'),
          },
        },
      },
    ],
    yAxis: [
      {
        type: 'value',
        axisLabel: {
          color: getCssVariableValue('--chart-font-color'),
        },
        axisTick: {
          lineStyle: {
            color: getCssVariableValue('--chart-y-line'),
          },
        },
        splitLine: {
          lineStyle: {
            color: getCssVariableValue('--chart-y-line'),
          },
        },
      },
    ],
  };
};

export { getTableColumns, charts, getChartOption };
